#ifndef SM4_UTILS_H
#define SM4_UTILS_H
#include <stddef.h>

// SM4密钥结构定义 - 重命名以避免与GmSSL冲突
typedef struct
{
    unsigned char key[16];
} SFTS_SM4_KEY;

// 生成随机SM4密钥
void sfts_generate_sm4_key(SFTS_SM4_KEY *key);

// ECB模式加密/解密
void sfts_sm4_ecb_encrypt(const unsigned char *in, unsigned char *out, const SFTS_SM4_KEY *key);
void sfts_sm4_ecb_decrypt(const unsigned char *in, unsigned char *out, const SFTS_SM4_KEY *key);

// CBC模式加密/解密
// void sfts_sm4_cbc_encrypt(const unsigned char *in, unsigned char *out, size_t length,
//                           const SFTS_SM4_KEY *key, const unsigned char *iv);
void sfts_sm4_cbc_decrypt(const unsigned char *in, unsigned char *out, size_t length,
                          const SFTS_SM4_KEY *key, const unsigned char *iv);

// 新增函数 - 使用GmSSL的SM4加密/解密接口
int sfts_generate_iv(unsigned char *iv, size_t len);
int sfts_sm4_encrypt(const unsigned char *key, const unsigned char *iv,
                     const unsigned char *plaintext, int plaintext_len,
                     unsigned char *ciphertext);
int sfts_sm4_decrypt(const unsigned char *key, const unsigned char *iv,
                     const unsigned char *ciphertext, int ciphertext_len,
                     unsigned char *plaintext);

#endif // SM4_UTILS_H